﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace A2DFramework.ValidationService.RuleValidators
{
    public class RuleRegularExpressionAttribute : RuleValidationAttribute
    {
        private RegularExpressionAttribute checker;

        public RuleRegularExpressionAttribute(string pattern)
            : this(string.Empty, pattern)
        {
        }

        public RuleRegularExpressionAttribute(string rule, string pattern)
            : base(rule)
        {
            checker = new RegularExpressionAttribute(pattern);
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            return checker.GetValidationResult(value, validationContext);
        }
    }
}